<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 * Smarty {opening_category} function plugin
 * @param array|null $params
 * @param Smarty $smarty
 */
function smarty_function_opening_category($params,$smarty){
	$smarty->CI->load->model('opening/opening_model');

	$html ="";
	$limit = 4;
	if (isset($params['limit'])){
		$limit = $params['limit'];
	}

	$html .= "<div class=\"featured-game\">\n";
	$openings = $smarty->CI->opening_model->get_openings(array('limit'=>$limit));
	$html .="<div class=\"featured-content\">"."\n";
	$html .="<ul class=\"glist\">"."\n";
	if (is_array($openings) && count($openings) > 0){
		foreach ($openings as $opening){
			$html .="<li class=\"gitem\">"
				."<div class=\"gimg\">
				        <div class=\"opening_1\">
				            Khai giảng ngày
				            <div class=\"opening_start\">". date_format(date_create($opening['start_time']), 'd/m/Y') . "</div>
							<div class=\"opening_time\">{$opening['time']}</div>
						</div>
						<div class=\"opening_2\">
							Kết thúc ngày
							<div class=\"opening_end\">" . date_format(date_create($opening['end_time']), 'd/m/Y') ."</div>
						</div>
					</div>"
				."<h2 class=\"opening_name\"><a href=\"{$opening['link']}\" title=\"{$opening['link']}\">{$opening['name']}</a>";
			$html .="</h2></li>";
			//$html .="<div class=\"ginfo\">".substr_utf8(strip_tags($opening['description']),0,100)."</div>"
			//	."</li>"."\n";
		}
	/*
	 * <div class="opening_1">
							Khai giảng ngày
							<div class="opening_start">24/02/2014</div>
							<div class="opening_time">2-4-6 (18h - 20h)</div>
						</div>
						<div class="opening_2">
							Kết thúc ngày
							<div class="opening_end">24/05/2014</div>
						</div>
	 */
    	$html .="</ul>"."\n";
    	$html .="</div>"."\n";
    	$html .= "</div>\n";
	}
	
	//var_dump($html); exit;
	return $html;
}
